<?php
/**
* 
*/
class ppComponent
{
	
	protected $_children;
	protected $_name;
	
	protected $_namedChildren;
	public function addNamedChild($child){
		$this->_namedChildren[$child->getName()] = $child;
	}
	public function getName(){
		return $this->_name;
	}
	
	protected $_parent;
	public function getParent(){
		return $this->_parent;
	}
		
	public function __construct()
	{
		$this->_init();
	}
	
	protected static $_counter = 0;
	protected function _generateName(){
		$this->_name='component'.++self::$_counter;
	}
	
	protected function _init(){
		$this->_generateName();
		$this->_createChildren();
	}
	
	protected function _createChildren(){
		$this->_children = array();
	}
	
	public function addChild(ppComponent $child,$named=false){
		if(!in_array($child,$this->_children)){
			$this->_children[] = $child;
			$child->_parent = $this;
			if($named){
				$this->_namedChildren[$child->getName()] = $child;
			}
		}
	}
	
	public function getChildAt($index){
		if(isset($this->_children[$index])){
			return $index;
		}
	}
	
	public function seialize(){
		return "";
	}
	
	public function deserialize(DOMElement $element){
		$name = $element->getAttribute('name');
		if(! empty($name)){
			$this->_name = $name;
		}
	}
	
	public function __get($name){
		return $this->_namedChildren[$name];
	}
	
	public static function create($type,$uri){
		if($uri==''){
			require_once(dirname(__FILE__).'/ui/ppHtmlTag.class.php');
			return new ppHtmlTag();
		}else{
			$class=str_replace(':','',$type);
			require_once(dirname(__FILE__).'/'.$uri.'/'.$class.'.class.php');
			return new $class;
		}
	}
}


?>